package com.sys.user.service;


import com.sys.core.exception.ClassCheckException;
import com.sys.user.base.service.BaseService;
import com.sys.user.domain.Xyrole;
import com.sys.user.persistence.XyroleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 角色
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class XyroleService extends BaseService<Xyrole> {
    @Autowired
    private XyroleMapper xyroleMapper;

    @Autowired
    public void setBaseMapper(XyroleMapper xyroleMapper) {
        this.baseMapper = xyroleMapper;
    }


    public void checkEntity(Xyrole xyrole) throws ClassCheckException {
        if(xyrole.getRoleId()!=null&&xyrole.getRoleId().length()>19){
            throw new ClassCheckException("角色角色ID不能超过19个字符");
        }
        if(xyrole.getName()!=null&&xyrole.getName().length()>19){
            throw new ClassCheckException("角色角色名不能超过19个字符");
        }
    }
    public void checkListEntity(List<Xyrole> listXyrole) throws ClassCheckException {

        for (Xyrole xyrole : listXyrole) {
            checkEntity(xyrole);
        }

    }

    public List<Xyrole> queryByUserId(String userId) {
        return xyroleMapper.queryByUserId(userId);
    }

    public List<Xyrole> queryAll() {
        return xyroleMapper.queryAll();
    }
}
